<?php
if (! defined ( 'BASEPATH' ))
    exit ( 'No direct script access allowed' );
class Access {
    private $CI;
	protected $user;

    public function __construct() {
        $this->CI = & get_instance ();
		$this->user = $this->CI->session->userdata ( 'user' );
		if (!isset($this->user['logged_in'])) {
			$this->user['logged_in'] = false;	
		}
    }
    
    public function setUser($user) {
    	$this->user = $user;
    }

    public function Allow($role = NULL) {
        if (! $this->user['logged_in']) {
            show_error ( lang ( 'access_denied' ), 500 );
        }
        elseif ($this->user['type_id'] != $role) {
            show_error ( lang ( 'access_denied' ), 500 );
        }
    }
    
    public function isRole($role = NULL) {
        if (! $this->user['logged_in']) {
            return false;
        }
        elseif ($this->user['type_id'] != $role) {
            return false;
        }
        
        return true;
    } 
	
    public function isLoggedIn() {
		return $this->user['logged_in'];
    }	

    public function getUserLang() {
    	return (isset($this->user['language_id'])) ? $this->user['language_id'] : $this->CI->config->item ( 'def_language_id' );
    }
    
    public function getUserId() {
    	return $this->user['id'];
    }
    public function getAdmin(){
    	return $this->user['admin'];
    }
}